Skip to content

feat: Claude Code compactions become compaction spans, with the summary that replaced the history (RIUS-1543) - #67

Merged
sudopower merged 1 commit into
mainfrom
factory/RIUS-1543
Oct 22, 2026
Merged

sudopower merged 1 commit into
mainfrom
factory/RIUS-1543

Conversation

@sudopower

Copy link
Copy Markdown
Member

Ticket: RIUS-1543

What changed

  • Re-vendored rius-semconv at v1.8.0 with scripts/sync-semconv.sh (--check ok).
  • Each compact_boundary transcript entry becomes a compaction CHAIN span: parent the open turn, else the root; end = boundary timestamp, start = end - durationMs; id from compaction:<uuid>. Attributes: kind=summarize, executor=client, trigger, tokens.before/after/dropped, messages.kept, id, summary.bytes. The summary text is added only when capture_content is on for the folder, scrubbed and capped at max_attr_bytes.
  • The first LLM span after each boundary gets gen_ai.conversation.compacted = true. Replaying or re-reading old boundaries re-arms nothing.
  • The isCompactSummary user entry no longer opens a turn; its text is attached to the compaction span (re-emitted with the same span id if it arrives in a later hook).
  • Malformed metadata never writes bad numbers; state fields are carried across resume (continuation.py).
  • docs/how-it-works.md has a short paragraph on the span.

Checks

  • python -m pytest -q: py3.12 1840 passed, 1 skipped; py3.13 1840 passed, 1 skipped; py3.9 without proto 1812 passed, 9 skipped.
  • scripts/sync-semconv.sh --check: matches v1.8.0.
  • New tests in tests/test_compaction.py (29) were each shown to fail against broken code.
  • Real session (Claude Code 2.1.304, --plugin-dir, loopback collector, isolated home): after about 72k tokens of context, /compact exported a compaction span with trigger=manual, tokens.before=72250, after=14036, dropped=58214, messages.kept=3, summary.bytes=5448, summary.text present. The next LLM span carried gen_ai.conversation.compacted = true, the one after did not. Recorded in the ticket's Progress.

Assumptions

  • A37: semconv v1.8.0 words the flag as "every LLM span whose context was compacted"; the ticket says the first LLM span after the boundary. I followed the ticket (a subset of the released wording), so a silent loss later in the same session is not masked. Step 5 (/clear event) is skipped: RIUS-1535 shows /clear starts a new transcript and session id.
  • Challenger: round 1 raised a P1 asking to mark every later call; it is the A37 choice above, and the final pass was clean with no waiver.

Notes for the reviewer

  • For a manual /compact, Claude Code writes the boundary and summary before the /compact command entries, so no turn is open at the boundary and the span's parent is the root (a sibling of the command turn).
  • The compaction span is emitted when the boundary is read and re-emitted with the same id once the summary is read; this relies on the backend collapsing same-id spans, as the LLM-span path already does.
  • Open PR rius-coding-agents #52 only touches README.md; no overlap.
  • No plugin release here; the version bump PR stays with the releaser.

…ry that replaced the history (RIUS-1543)

A compact_boundary entry is exported as a compaction span (kind summarize, executor client, trigger, tokens before/after/dropped, messages kept, id, summary bytes, and the summary text when content capture is on). The first LLM call after it carries gen_ai.conversation.compacted. The isCompactSummary entry is no longer a user turn. Re-vendors rius-semconv v1.8.0.

Signed-off-by: Kiran <nkirandroid@gmail.com>
@sudopower

Copy link
Copy Markdown
Member Author

factory/review: PASS @ f97620d

Reviewed RIUS-1543 at head f97620dea4c575423802095ffd8e3477f617d9dd.

Verified

  • RIUS_SEMCONV=/opt/glass0/rius-semconv scripts/sync-semconv.sh --check: up to date. The GitHub fetch got a connection reset, so I checked against the local v1.8.0 checkout.

  • uv run --no-project --python 3.12 --with 'pytest>=7.0' --with 'opentelemetry-proto==1.43.0' python -m pytest -q -p no:cacheprovider: 1840 passed, 1 skipped.

  • py3.9 floor run of tests/test_compaction.py and tests/test_transcript.py: 44 passed, 1 skipped.

  • Mutation: 22 mutants, 20 killed. Killed:

    • the replay guard (<=→<, and turned off);
    • the compact_next reset and the summary continue;
    • clearing open_compaction;
    • the parse admit (not admitted, and any system admitted);
    • kept counted from uuids;
    • dropped always;
    • start from durationMs;
    • the trigger filter;
    • the content gate on the summary text, and summary bytes counted as chars;
    • parent turn vs root;
    • _count accepting bool or negative values;
    • the key_prefix span id;
    • the compacted attribute;
    • the context reset on the summary;
    • last_ns set by the boundary.

    The 2 survivors are in F1.

  • Premise, checked against real local transcripts (counts only):

    • 1601 compact_boundary entries, all Claude Code 2.1.x.
    • The compactMetadata keys match what is read. Trigger is only auto (1569) or manual (32), and postTokens is never greater than preTokens.
    • 182 boundaries are sidechain compactions in subagent files. They go through emit_entries with new_scope(), and test_a_compaction_in_a_subagent_hangs_off_the_agent_span covers them.
  • Session continuation (continued-in), across 44 old/new pairs (3 with boundaries):

    • Claude Code copies only the latest boundary into the new transcript, with its original uuid, so drop_copied skips it.
    • Every other boundary in a new transcript has a new uuid and a time after the switch.
    • No copied entry follows a new one.
  • Other readers of system entries:

    • subagents.py filters by kind.
    • The exporter takes entries[0].cwd (a boundary carries cwd).
    • copied_uuids and drop_copied match by uuid.
  • Privacy: the persisted open_compaction holds sizes and ids only. The summary text lives only in the batch.

Good call: sending the boundary span at once and filling in the summary under the same span id. It follows the existing pattern for a response that grows, and a hook that reads between the two lines loses nothing.

Findings (non-blocking)

  • F1 (P3, tests): two mutants survive.

    • (a) _MOVED without open_compaction, compact_next and last_compaction (scripts/rius_cc/continuation.py:130). No test hands a session over between a boundary and its summary or next call. If the hand-over happens there, the flag or the summary would be lost.
    • (b) before >= after → before > after (scripts/rius_cc/spans.py, _open_compaction). tokens.dropped = 0 at equal sizes is never asserted.
  • F2 (P3): a <synthetic> assistant entry right after a boundary takes the flag (scripts/rius_cc/spans.py, _generation_for). The real first call then goes unflagged. In local transcripts this happened for 2 of 1598 boundaries. Suggested fix: don't consume compact_next for message.model == "<synthetic>", and add a test.

  • F3 (P3): the is_compact_summary branch has no replay guard. On a re-read from an earlier offset (a rewound or shrunk file) while a newer boundary's summary is still pending, an OLD summary attaches to the newer span and clears open_compaction. The correct summary then finds nothing to attach to. Narrow: it needs a hook to read between the boundary and its summary, then a rewind. Suggested fix: when the replay guard skips a boundary, also skip the summary that follows it.

A Sonnet challenger was used. It agreed with F1 and raised F2 and F3; I checked both against the code, and F2 against real transcripts.

Not verified

  • No live Claude Code session. I relied on the builder's recorded /compact check (2.1.304) and on the real transcript shapes above.
  • The backend collapsing the twice-sent compaction span. I checked that the generation re-send pattern it relies on already exists; I did not run it against argus-core.
  • /clear (A37, step 5 skipped) is out of scope here.

@sudopower
sudopower merged commit d50b391 into main Oct 22, 2026
22 checks passed
@sudopower
sudopower deleted the factory/RIUS-1543 branch October 22, 2026 02:48
sudopower added a commit that referenced this pull request Oct 27, 2026
Merge main (#71-#74) into the release branch and join the two 0.8.0
sections into one entry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant